import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/page/layout/layout.vue'
import { commonRouter } from './common-router'

const routes: Array<RouteRecordRaw> = [{
    path: '/',
    redirect: '/index',
}, {
    path: '',
    name: 'layout',
    component: () => import('@/page/layout.vue'),
    children: commonRouter
}]

const router = createRouter({
    history: createWebHistory(),
    routes,
})

// 路由拦截相关
// // let googleServer: GoogleTagServer = new GoogleTagServer()
// const whiteList = [
//     { pattern: /^\/administrator\/login\/*/ },
// ]
// router.beforeEach((to, from, next) => {
//     if (to.name && from.name && to.name === from.name) {
//         next(false)
//         return false
//     } else {
//         const token = window.sessionStorage.getItem('token') || ''
//         if(!token) {
//             let pass = whiteList.some((item: any) => {
//                 if (typeof (item) === 'object' && item.pattern) {
//                     return item.pattern.test(to.fullPath)
//                 }
//                 return to.fullPath === item
//             })
//             if(to.fullPath && !pass) {
//                 let regx = /administrator/g
//                 if(!regx.test(to.fullPath)) router.push({ name: 'userIdLogin' })
//                 else router.push({ name: 'administratorLogin' })
//             } else {
//                 next()
//             }
//         } else {
//             next()
//         }
//     }
// })
export default router
